var path;
function initPath(ctx){
	path=ctx;
}
//初始化表格
function initTable(id,queryParams,columns,url){
	 $('#'+id+'').bootstrapTable({
	    	method:'GET',
	        dataType:'json',
	        contentType: "application/x-www-form-urlencoded",
	        cache: false,
	        striped: true,                              //是否显示行间隔色
	        sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
	        url:url,
	        height: $(window).height() - 110,
	        width:$(window).width(),
	        /* showColumns:true, */
	        pagination:true,
	        queryParams : queryParams,
	        minimumCountColumns:2, 
	        pageNumber:1,                       //初始化加载第一页，默认第一页
	              pageSize:10,                       //每页的记录行数（*）
	              pageList: [5,10,15,25,50,100],        //可供选择的每页的行数（*）
	              uniqueId: "id",                     //每一行的唯一标识，一般为主键列
	        showExport: true,                    
	        exportDataType: 'all',
	        responseHandler: responseHandler,
	        columns: columns
	    });
}
function responseHandler(res) { 
	  console.log(res)
  if (res) {
      return {
          "rows" : res.data,
          "total" : res.totalRecord
      };
  } else {
      return {
          "rows" : [],
          "total" : 0
      };
  }
}
//表格顶部条件查询
//function topDoQuery(id,queryParams,columns,url){
//   // $('#'+id+'').bootstrapTable('refresh');    //刷新表格
//	initTable(id,queryParams,columns,url);
//}
//表格分页查询
function doQuery(id){
	    $('#'+id+'').bootstrapTable('refresh');    //刷新表格
	}
function doQuery1(id,params){
	 $('#'+id+'').bootstrapTable('refreshOptions',params);
}
var serialize = function(form){
    var $form = (typeof(form)=="string" ? $("#"+form) : form);
    var dataArray =  $form.serializeArray();
   var result={};
    $(dataArray).each(function(){
        //如果在结果对象中存在这个值，那么就说明是多选的情形。
        if(result[this.name]){
            //多选的情形，值是数组，直接push
            result[this.name].push(this.value);
        }else{
            //获取当前表单控件元素
            var element = $form.find("[name='"+ this.name +"']")[0];
            //获取当前控件类型
            var type = ( element.type || element.nodeName ).toLowerCase();
            //如果控件类型为多选那么值就是数组形式，否则就是单值形式。
            result[this.name] = (/^(select-multiple|checkbox)$/i).test(type) ? [this.value] : this.value;
        }
    });
    return result;
};
//初始化上传文件控件
function initFileInput(id){
	$("#"+id+"").fileinput({
        previewFileType: "image", 
        browseClass: "btn btn-success",
        browseLabel: "Please Selected",
        browseIcon: "<i class=\"glyphicon glyphicon-picture\"></i> ",
        removeClass: "btn btn-danger",
        removeLabel: "Delete",
        removeIcon: "<i class=\"glyphicon glyphicon-trash\"></i> ",
        uploadClass: "btn btn-info",
        uploadLabel: "Upload",
        uploadIcon: "<i class=\"glyphicon glyphicon-upload\"></i> ", 
        uploadUrl: path+"pcphoto/pcphotoImg?needsThumb=1",
       /* allowedFileExtensions: ["jpg", "png", "gif"],	 */
        maxFileCount: 5,
        width:200,
        height:200,
        resizeImage: true
        	}).on('filepreupload', function(data) {
                console.log(data);
        	    $('#kv-success-box').html('');
        	}).on('fileuploaded', function(event, data) {
        		  console.log(data);
        		 if(data.response.code==0){
        				var im =$('#imgId').val();
        				var str="";
        				if(im!=""){
        					str=im+",";
        				}
        				$("#imgId").val(str+data.response.data);   
        		 }else{
        			 var txt=data.response.msg;
				  window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.info);
        			 
        		 }
        	    $('#kv-success-box').append(data.response.link);
        	    $('#kv-success-modal').modal('show');
        	}).on('fileclear', function(event, key) {  
        	       alert("图片被移除");
        	      $("#imgId").val(null); 
        	});
}


function cacel(){
	layer.closeAll();
}
//时间格式化
	function timeStamp2String(time){
		var str='';
		if(time==null){
			str= '';
		}else{
			 var datetime = new Date();
			    datetime.setTime(time);
			    var year = datetime.getFullYear();
			    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
			    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
			    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
			    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
			    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
			    str= year + "-" + month + "-" + date+" "+hour+":"+minute+":"+second
		}
		 return str;
	}
	//时间格式化
	function timeDateString(time){
	    var str='';
		if(time==null){
			str= '';
		}else{
			 var datetime = new Date();
			    datetime.setTime(time);
			    var year = datetime.getFullYear();
			    var month = datetime.getMonth() + 1 < 10 ? "0" + (datetime.getMonth() + 1) : datetime.getMonth() + 1;
			    var date = datetime.getDate() < 10 ? "0" + datetime.getDate() : datetime.getDate();
			    var hour = datetime.getHours()< 10 ? "0" + datetime.getHours() : datetime.getHours();
			    var minute = datetime.getMinutes()< 10 ? "0" + datetime.getMinutes() : datetime.getMinutes();
			    var second = datetime.getSeconds()< 10 ? "0" + datetime.getSeconds() : datetime.getSeconds();
			    return year + "-" + month + "-" + date
		}
		 return str;
	}